#cmake_minimum_required(VERSION 3.17)
#project(ffplayer-demo)

set(TOP_DIR ${CMAKE_SOURCE_DIR})

#include(${TOP_DIR}/histreamer/engine/CMakeLists.txt)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

message(STATUS "top_dir: ${TOP_DIR}")

if (MSVC)
    #    message(STATUS ${CMAKE_EXE_LINKER_FLAGS})
    #    set(CMAKE_EXE_LINKER_FLAGS "/MACHINE:X64")
    set(CMAKE_CXX_FLAGS "/W4 -DMSVC_VMG_ENABLED /vmg")
    set(ffmpeg_lib_path ${TOP_DIR}/3rdparty/ffmpeg/windows/lib)
    set(ffmpeg_inc_path ${TOP_DIR}/3rdparty/ffmpeg/windows/include)
    set(sdl_lib_path ${TOP_DIR}/3rdparty/SDL2.0/windows/lib/x64)
    set(sdl_inc_path ${TOP_DIR}/3rdparty/SDL2.0/include)
elseif (MINGW)
    set(ffmpeg_lib_path ${TOP_DIR}/3rdparty/ffmpeg/windows/lib)
    set(ffmpeg_inc_path ${TOP_DIR}/3rdparty/ffmpeg/windows/include)
    set(sdl_lib_path ${TOP_DIR}/3rdparty/SDL2.0/windows/lib/x64)
    set(sdl_inc_path ${TOP_DIR}/3rdparty/SDL2.0/include)
    set(curl_lib_path ${TOP_DIR}/3rdparty/curl/lib/windows)

    file(GLOB ffmpeg_shared_libraries ${ffmpeg_lib_path}/../bin/*.dll)
    file(GLOB sdl_shared_libraries ${sdl_lib_path}/*.dll)
    file(GLOB curl_shared_libraries ${curl_lib_path}/*.dll)
    file(COPY ${ffmpeg_shared_libraries} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
    file(COPY ${sdl_shared_libraries} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
    file(COPY ${curl_shared_libraries} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
else ()
    set(CMAKE_CXX_FLAGS "-g -ggdb3 -O0 -std=c++11 -Wall")
    set(ffmpeg_lib_path /usr/local/ffmpeg/lib)
    set(ffmpeg_inc_path /usr/local/ffmpeg/include)
    set(sdl_lib_path /usr/lib/x86_64-linux-gnu/)
    set(sdl_inc_path /usr/include/SDL2)
endif ()

set(CMAKE_VERBOSE_MAKEFILE ON)

include_directories(
        ${ffmpeg_inc_path}
        ${sdl_inc_path}
        ${PLAYER_INTERFACE_DIR}
        ${TOP_DIR}/histreamer/engine/include
        ${TOP_DIR}/histreamer/engine/factory
)

set(PLAYER_SRCS
        ${TOP_DIR}/demo/windows/player.cpp
        )

set(RECORDER_SRCS
        ${TOP_DIR}/demo/windows/recorder.cpp
        )

set(SRCS
        ${HISTREAMER_SRCS}
        ${3RDPARTY_SRCS}
        ${TOP_DIR}/histreamer/engine/foundation/osal/utils/util.cpp
        )

message(STATUS "${ffmpeg_lib_path}")
link_directories(
        ${ffmpeg_lib_path}
        ${sdl_lib_path}
        ${curl_lib_path}
)

message(STATUS "Windows demo OHOS_LITE is ${OHOS_LITE}")
if (${OHOS_LITE})
    add_definitions(-DOHOS_LITE)
endif ()

if (MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
    link_libraries(
            #histreamer
            avformat
            avcodec
            avutil
            avdevice
            avfilter
            swresample
            swscale
            SDL2main
            SDL2
            dinput8 dxguid user32 gdi32 winmm imm32 ole32 oleaut32 shell32
            setupapi version uuid legacy_stdio_definitions
    )
else ()
    link_libraries(
            histreamer
    )
endif ()

add_executable(histreamer_player ${SRCS} ${PLAYER_SRCS})
add_executable(histreamer_recorder ${SRCS} ${RECORDER_SRCS})